<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="version" content="Alidao v1.0 20151012">
    <meta http-equiv="Cache-Control" content="must-revalidate,no-cache">
    <meta http-equiv="x-dns-prefetch-control" content="on" />
    <title>基本信息评估</title>
    <link type="text/css" rel="stylesheet" href="${ctx}/static/healthassess/css/common.css" />
    <link rel="stylesheet" href="${ctx}/static/healthassess/css/list.css">
    <link rel="stylesheet" href="${ctx}/static/healthassess/css/health.css">
</head>

<body>
<div class="container health">
    <div class="question-list" id="question_list" style="display:none">
        <h4 class="ps">本评估适用于18周岁以上</h4>
    </div>
    <p class="tips" id="tips"></p>
    <footer class="footer btn-one" style="display:none">
        <a class="bder-radius-4" id="submit" href="javascript:void(0);" onclick="submit()">提交</a>
    </footer>
    <section class="result" id="result" style="display:none">${result}
        <footer class="footer btn-one">
            <a class="bder-radius-4 active"   href="javascript:void(0);" onclick="redo()">重新评估</a>
        </footer>
    </section>
</div>
<script src="${ctx}/static/healthassess/js/jquery-2.1.4.min.js"></script>
<script src="${ctx}/static/healthassess/js/jquery.mobile.custom.min.js"></script>
<script src="${ctx}/static/healthassess/js/common.js"></script>
<script>
    var sex;
    var questionLength=9;
    var questionJson = [{
        type: "radio",
        question: "您的性别是：",
        answer: {
            answerArray: ["男", "女", ],
            <c:if test="${jmjbxx!=null}">checked:"${jmjbxx.CNAME_SEX.text}"</c:if>
        }
    }, {
        type: "input",
        question: "您的年龄是",
        <c:if test="${jmjbxx!=null}"> value:${jmjbxx.age}</c:if>
    }, {
        type: "input",
        question: "您的身高（cm)是"
    }, {
        type: "input",
        question: "您的体重（kg）是"
    }, {
        type: "input",
        question: "您的腰围（cm）是"
    }, {
        type: "radio",
        question: "您有过敏史么?",
        answer: {
            answerArray: ["有", "无", ],
            hide: [{
                type: "checkbox",
                question: "您的过敏类型有（可多选）", //您有过敏史，建议您：避免易过敏的物质接触，出现过敏反应及时就医。
                answer: ["食物", "药物", "接触物", ]
            }, ]
        }
    }, {
        type: "radio",
        question: "您的婚姻状态是",
        answer: {
            answerArray: ["已婚", "未婚",],
            <c:if test="${jmjbxx!=null}">checked:"${jmjbxx.MARRIAGE}"</c:if>
        }
    }, {
        type: "radio", // 只有女性才会做8,9两题
        question: "您月经初潮年龄是：",
        answer: {
            answerArray: ["小于12岁", "12岁", "13岁", "14岁或14岁以上" ]
        }
    }, {
        type: "radio", // radio  checkbox  input
        question: "您生第一个孩子的年龄：",
        answer: {
            answerArray: ["小于20岁", "20-24岁", "25-29岁", "30或30岁以上", "从未生育过",]
        }
    }];
    $(function() {
        if (${not empty result}) {
            $("#result").show();
            return;
        }else{
            $("#result").siblings("div,footer").show();
        }
        for (var i = 1; i <= 4; i++) {
            $(".question").eq(i).find('input').attr('type', 'number');
        };
        select_click();
        verify();
    });
    var select_click = function() {
        $(".list").each(function(index) {
            $(this).find("li").tap(function() {
                onSelecting($(this));
                getAnswer(index, $(this));
                //set question
                setQuestion(index, $(this));
                verify();
            });
        });
    };


    function setQuestion(index, t) {
        if (index == 0) {
            var number = $(t).index();
            if (number == 0) {
                $(".question").eq(7).hide();
                $(".question").eq(8).hide();
                sex = "男";
            } else {
                $(".question").eq(7).show();
                $(".question").eq(8).show();
                sex = "女";
            }
        } else if (index == 1) {
            var number = $(t).index();
            if (number == 0) {
                $(".question").eq(5).find('.hide').show();
            } else if (number == 1) {
                var oHide = $(".question").eq(5).find('.hide');
                oHide.slideUp();
                oHide.find("input").removeAttr('checked');
                oHide.find('li').removeClass('active');
            }
        }
    }
    var resultHtml;
    var sum;
    // 计算BMI
    function BMI(){
        //BMI
        var age = $(".question").eq(1).find("input").val()
        var tall = $(".question").eq(2).find("input").val();
        var tall_d = (tall / 100) * (tall / 100);
        var weight = $(".question").eq(3).find("input").val();
        var BMI = weight / tall_d;
        BMI = round(BMI, 1);
        sum=BMI;
        result(BMI);
    }
    // BMI result
    function  result(BMI){
        resultHtml="";
        var waistline = $(".question").eq(4).find("input").val();
        if (BMI < 18.5) {
            resultHtml = '<div class="result-list">' +
            '<h4>您的BMI为' + BMI + ',属于体重过轻,请您：</h4>' +
            '<ul>' +
            '<li><p>1.积极查找原因，如饮食不当、减肥过度、疾病因素。</p></li>' +
            '<li><p>2.适当增加营养。</p></li>' +
            '</ul>' +
            '</div>';
        } else if (BMI >= 18.5 && BMI <= 23.9) {
            resultHtml = '<div class="result-list">' +
            '<h4>您的BMI为' + BMI + '<br/>体重正常,保持良好的健康生活</h4>' +
            '<ul>' +
            '<li><p>1.合理饮食，保证合理的膳食和均衡的营养。</p></li>' +
            '<li><p>2.增加户外体育锻炼活动，每天保证一定运动量。</p></li>' +
            '<li><p>3. 戒烟、限酒, 及时调整生活规律，劳逸结合，保证充足睡眠。</p></li>' +
            '<li><p>4.保持良好的心态。</p></li>' +
            '<li><p>5.定期体检，注意防癌检查。</p></li>' +
            '<li><p>6.年满35周岁每年至少一次血压监测。</p></li>' +
            '</ul>' +
            '</div>';
        } else if (BMI >= 24 && BMI <= 27.9) {
            resultHtml = '<div class="result-list">' +
            '<h4>您的BMI为' + BMI + ',属于体重超重,请您：</h4>' +
            '<ul>' +
            '<li><p>1.合理平衡膳食，保证适当运动和足够睡眠，减少压力，维持良好情绪。</p></li>' +
            '<li><p>2.避免暴饮暴食的不良饮食习惯BMI≥28您的体重属于肥胖，与多种疾病如2型糖尿病、血脂异常、高血压、冠心病、脑卒中、肿瘤等密切相关。</p></li>' +
            '</ul>' +
            '</div>';
        }

        if (sex == "男" && waistline >= 85 || sex == "女" && waistline >= 80) {
            resultHtml += '<div class="result-list">' +
            '<h4>您属于腹型肥胖，建议您：</h4>' +
            '<ul>' +
            '<li><p>1.合理平衡膳食，保证适当运动和足够睡眠，减少压力，维持良好情绪。</p></li>' +
            '<li><p>2.避免暴饮暴食的不良饮食习惯。</p></li>' +
            '</ul>' +
            '</div>';
        }
    }

    function verify(){
        if(sex=="男"){
            if($(".hide").attr("data-status")=="do"){
                questionLength=8;
            }else{
                questionLength=7;
            }
        }else if(sex=="女"){
            if($(".hide").attr("data-status")=="do"){
                questionLength=10;
            }else{
                questionLength=9;
            }
        }
        var isDo=$("[data-status='do']");
        if(isDo.length<questionLength){
            $("#submit").removeClass('active').attr("onclick","");
        }else{
            $("#submit").addClass('active').attr("onclick","submit()");
        }
    }


    function submit() {
        getData();
        BMI();
        /**  if(sum>27.9){*/
        if(sum>127.9){
            $("#tips").html("请填写真实的身高和体重").show();
        }else{
            var result = resultHtml;
            var questionArray = dataArr;
            var questionnaire_id = "0";
            var questionnaire = "基本信息评估";
            var data = {
                uid: ${uid},
                questionnaireId: questionnaire_id,
                questionnaire: questionnaire,
                questionArray: JSON.stringify(questionArray),
                result: result,
                score: sum
            };
            $.ajax({
                url: '${ctx}/h5/health/assessment/save',
                type: 'post',
                data: data,
                dataType:"json",
                success:function(){

                },
                error:function(){

                }
            })
            $(window).scrollTop(0);
            $("#result footer").before(resultHtml);
            $("#result").siblings('div,footer').hide();
            $("#result").show();
            $("#tips").hide();
        }

    }

    function nocl(){

    }


</script>


</body>

</html>
